﻿<%@ Control Language="C#" ClassName="PaymentsMB" Inherits="Dimok.Web.UI.TableControl" %>
<script runat="server">
	public int LoanID { get { return (int)Lib.GetProperty(Parent, "LoanID"); } }
	public int PaymentID { get { return GridViewEx.SelectedValue == null ? 0 : int.Parse("0" + GridViewEx.SelectedValues["ID"]); } }
	System.Drawing.Color GreenColor { get { return System.Drawing.Color.FromArgb(0x59, 0x86, 0x2D); } }
	System.Drawing.Color RedColor { get { return System.Drawing.Color.FromArgb(0x99, 0x33, 0x66); } }
	protected override void OnInit(EventArgs e) {
		base.OnInit(e);
		grv.RowInserting += grv_RowInserting;
		GridViewEx.RowDataBound += GridViewEx_RowDataBound;
		GridViewEx.RowCreated += new GridViewRowEventHandler(GridViewEx_RowCreated);
		//System.Drawing.Color.DarkGreen
	}

	void GridViewEx_RowCreated(object sender, GridViewRowEventArgs e) {
		if (e.Row.DataItem == null) return;
		var row = ((DataRowView)e.Row.DataItem).Row;
		if (row["PaymentBalance"] == DBNull.Value) row["PaymentBalance"] = 0;
	}

	void GridViewEx_RowDataBound(object sender, GridViewRowEventArgs e) {
		if (e.Row.DataItem == null) return;
	}
	void grv_RowInserting(object sender, GridViewInsertEventArgs e) {
		e.InsertingValues["LoanID"] = LoanID;
	}
	
</script>
<asp:UpdatePanel ID="upPayments" UpdateMode="Always" runat="server">
	<ContentTemplate>
	<UI:GridViewMB ID="grv" runat="server" AutoGenerateColumns="False" ShowDelete="false"
		AllowSorting="true" DataKeyNames="ID" DataSourceID="ds" RowStyle-BackColor="#ffffea" >
	<Columns>
		<asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="true" SortExpression="ID" ItemStyle-HorizontalAlign="Right" />
		<asp:BoundField DataField="PaymentNumber" HeaderText="Pmt#" ReadOnly="true" SortExpression="PaymentNumber" ItemStyle-HorizontalAlign="Right" />
		<asp:TemplateField HeaderText="Pmt$" SortExpression="Amount" ItemStyle-HorizontalAlign="Right">
			<ItemStyle Font-Bold="true" />
			<ItemTemplate><%#Eval("Amount")%></ItemTemplate>
			<%--<EditItemTemplate><asp:TextBox ID="txtAmount" Text='<%#Bind("Amount")%>' runat="server"/></EditItemTemplate>--%>
			<FooterTemplate><asp:TextBox ID="Amount" runat="server" /></FooterTemplate>
		</asp:TemplateField>
		<asp:TemplateField HeaderText="DatePaid" SortExpression="DatePaid">
			<ItemStyle Font-Bold="true" />
			<ItemTemplate><%#Eval("DatePaid","{0:MM/dd/yyyy}")%></ItemTemplate>
			<%--<EditItemTemplate><asp:TextBox ID="txtDatePaid" Text='<%#Bind("Datepaid","{0:MM/dd/yyyy}")%>' runat="server" /></EditItemTemplate>--%>
			<FooterTemplate><asp:TextBox ID="DatePaid" runat="server" /></FooterTemplate>
		</asp:TemplateField>
		
		<asp:BoundField DataField="DateScheduled" DataFormatString="{0:MM/dd/yyyy}" ReadOnly="true" HeaderText="DateSched"	SortExpression="DateScheduled" />
		<asp:BoundField DataField="PrincipalBalance" ItemStyle-Font-Bold="true" ReadOnly="true" HeaderText="PrnBal" DataFormatString="{0:n}" SortExpression="PrincipalBalance" ItemStyle-HorizontalAlign="Right" />
		<asp:BoundField DataField="ExpectedBalance" HeaderText="ExpBal" ReadOnly="true" DataFormatString="{0:n}" SortExpression="ExpectedBalanceBalance" ItemStyle-HorizontalAlign="Right" />
		<asp:TemplateField HeaderText="PmtBal" SortExpression="PaymentBalance" ItemStyle-HorizontalAlign="Right" >
			<ItemTemplate><asp:Label id="spnPaymentBalance" runat="server" Text='<%#Eval("PaymentBalance")%>' ForeColor='<%#((decimal)Eval("PaymentBalance"))>=0?GreenColor:RedColor %>' Font-Bold="true" /></ItemTemplate>
		</asp:TemplateField>
		<asp:BoundField DataField="DPD0" HeaderText="DPD" ReadOnly="true" DataFormatString="{0:n0}" ItemStyle-Font-Bold="true" SortExpression="DPD0" ItemStyle-HorizontalAlign="Right" />
		<asp:TemplateField HeaderText="Prn Part" SortExpression="PrincipalPart" ItemStyle-HorizontalAlign="Right">
			<ItemStyle Font-Bold="true" />
			<ItemTemplate><%#Eval("PrincipalPart")%></ItemTemplate>
			<%--<EditItemTemplate><asp:TextBox ID="txtPrincipalPart" Text='<%#Bind("PrincipalPart")%>' runat="server"/></EditItemTemplate>--%>
<%--			<FooterTemplate><asp:TextBox ID="PrincipalPart" runat="server" /></FooterTemplate>--%>
		</asp:TemplateField>
		<asp:TemplateField HeaderText="Int Part" SortExpression="InterestPart" ItemStyle-HorizontalAlign="Right">
			<ItemStyle Font-Bold="true" />
			<ItemTemplate><%#Eval("InterestPart")%></ItemTemplate>
			<%--<EditItemTemplate><asp:TextBox ID="txtInterestPart" Text='<%#Bind("InterestPart")%>' runat="server"/></EditItemTemplate>--%>
			<FooterTemplate><asp:TextBox ID="InterestPart" runat="server" /></FooterTemplate>
		</asp:TemplateField>
		<asp:BoundField DataField="InterestBalance" HeaderText="Int Bal" ReadOnly="true" SortExpression="InterestBalance" ItemStyle-HorizontalAlign="Right" />
		<asp:BoundField DataField="LateFeePart" HeaderText="LateFeePart" ReadOnly="true" SortExpression="LateFeePart" ItemStyle-HorizontalAlign="Right" />
		<asp:BoundField DataField="LateFeeBalance" HeaderText="LF Bal" ReadOnly="true" SortExpression="LateFeeBalance" ItemStyle-HorizontalAlign="Right" />
		<asp:BoundField DataField="NSFFeePart" HeaderText="NsfFeePart" ReadOnly="true" SortExpression="NSFFeePart" ItemStyle-HorizontalAlign="Right" />
		<asp:BoundField DataField="NSFFeeBalance" HeaderText="NSF Bal" ReadOnly="true" SortExpression="NSFFeeBalance" ItemStyle-HorizontalAlign="Right" />
		<asp:BoundField DataField="DateNext" DataFormatString="{0:MM/dd/yyyy}" HeaderText="DateNext" ReadOnly="true" SortExpression="DateNext" />
		<asp:BoundField DataField="WaterFall" HeaderText="Water Fall" ReadOnly="true"	SortExpression="WaterFall"  ItemStyle-HorizontalAlign="Center" />
		<asp:TemplateField HeaderText="Status" SortExpression="Status">
		<ItemTemplate>
			<%#Eval("Status")%>
			<asp:ImageButton Height="16" Width="16" ImageUrl="~/images/History.gif" runat="server" OnClientClick=<%#Eval("ID","statusHistory(this,{0},\"t_Payment\");return false")%> CssClass="TipMe" style="cursor:hand" ToolTip="Click to see hostory"/>
		</ItemTemplate>
		<EditItemTemplate>
		<DS:StateFlowNextStatesDataSource StateFromID='<%#Eval("StatusID")%>' ID="dsStatuses" runat="server" />
		<asp:DropDownList SelectedValue='<%#Bind("StatusID")%>' DataSourceID="dsStatuses" DataTextField="StateTo" DataValueField="StateToID" ID="StatusID" runat="server" />
		</EditItemTemplate>
		</asp:TemplateField>
		<asp:BoundField DataField="StatusUser" HeaderText="User" SortExpression="StatusUser" ReadOnly="true" />
		<asp:BoundField DataField="StatusDate" HeaderText="StatusDate" ReadOnly="true" SortExpression="StatusDate" DataFormatString="{0:MM/dd/yyyy}" />
		<asp:BoundField DataField="IntAddOn" HeaderText="IntAddOn" ReadOnly="true" SortExpression="IntAddOn" />
	</Columns>
</UI:GridViewMB>
</ContentTemplate>
</asp:UpdatePanel>

<DS:PaymentsMBDataSource EmtyRowPolicy="OnlyIfEmpty" ID="ds" SelectList="*,ISNULL(PaymentBalance,0) PaymentBalance0" runat="server" OrderBys="DatePaid,ID">
	<SelectParameters>
		<asp:ControlParameter PropertyName="Page.LoanID" Name="LoanID" Type="Int32" />
	</SelectParameters>
</DS:PaymentsMBDataSource>
